package adapter;

import java.util.List;

import com.cqtczh.qhd.driver.R;

import javabeen.Area;
import javabeen.CarRoutHomeBeen;
import adapter.CarRouteANDHomeListAdapter.ViewHolder;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author 作者 E-mail:
 * @date 创建时间：2015-6-7 下午5:54:48
 * @version 1.0
 * @parameter
 * @since
 * @return
 */
public class AreaAdapt extends BaseAdapter {
	public List<Area> CarRoutHomeBeen;
	private int xml;
	private Context context;
	private LayoutInflater inflater;

	public AreaAdapt(Context context, List<Area> CarRoutHomeBeen, int xml) {
		this.CarRoutHomeBeen = CarRoutHomeBeen;
		this.xml = xml;
		this.context = context;
		if (this.context != null) {
			this.inflater = LayoutInflater.from(context);
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return CarRoutHomeBeen.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return CarRoutHomeBeen.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ViewHolder viewHolder;
	//	boolean flag=false;
		if (convertView == null) {
			convertView = inflater.inflate(xml, null);
			viewHolder = new ViewHolder();
			viewHolder.textView1 = (TextView) convertView
					.findViewById(R.id.are_name);
			viewHolder.imageView=(ImageView) convertView.findViewById(R.id.are_check);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		Area data = CarRoutHomeBeen.get(position);
		if (data != null) {

			viewHolder.textView1.setText(data.getAreaname());// (R.id.myorder_content_flowid);
			if (data.isFlag()) {
				viewHolder.imageView.setImageResource(R.drawable.check);
			}else {
				viewHolder.imageView.setImageResource(R.drawable.unchecked);
			}
		}

		return convertView;
	}
	
	
	public List<Area> getAdapter(){
		return this.CarRoutHomeBeen;
		
	}

	class ViewHolder {
		TextView textView1;
		ImageView imageView;
	}
}
